<template>
	<view class="to-attendance-box">
		<view class="course-info">
			<view class="item-top">
				<view class="course-title">{{courseDetail.course.title}}</view>
				<view class="course-time">{{courseDetail.date}}</view>
			</view>
			<view class="item-center" v-if="courseDetail.address">
				<image src="@/static/common/address.png" class="address-icon"></image>
				<view class="address-info">
					<text class="address-name">{{courseDetail.address}}</text>
				</view>
			</view>
			<view class="item-bottom">
				<view class="bottom-info">
					<text class="label">学校：</text>
					<text class="value">{{courseDetail.school.title}}</text>
				</view>
				<view class="bottom-info">
					<text class="label">班级：</text>
					<text class="value">{{courseDetail.banji.title}}</text>
				</view>
				<view class="bottom-info">
					<text class="label">学期：</text>
					<text class="value">{{courseDetail.term.title}}</text>
				</view>
				<view class="bottom-info">
					<text class="label">班级人数：</text>
					<text class="value">{{courseDetail.banji.student_num}}人</text>
				</view>
				<view class="bottom-info">
					<text class="label">上课地点：</text>
					<text class="value">{{courseDetail.course.place}}</text>
				</view>
				<view class="bottom-info">
					<text class="label">上课时间：</text>
					<text class="value">第{{courseDetail.schedule.num}}节({{courseDetail.schedule.class_time}})</text>
				</view>
			</view>
		</view>

		<view class="student-list-box" v-if="courseDetail&&courseDetail.student&&courseDetail.student.length>0">
			<view class="student-list">
				<view class="student-item" v-for="(student, index) in courseDetail.student" :key="index">
					<view class="student-name">{{student.name}}</view>
					<view class="student-no">{{student.no}}</view>
					<view class="student-status">
						<view :class="student.status==1?'tag-box success':'tag-box'">正常</view>
						<view :class="student.status==2?'tag-box late':'tag-box'">迟到</view>
						<view :class="student.status==3?'tag-box early':'tag-box'">早退</view>
						<view :class="student.status==4?'tag-box absent':'tag-box'">缺勤</view>
					</view>
				</view>
			</view>
		</view>

		<view class="upload-box">
			<view class="upload-header">
				<view class="upload-title">上传照片</view>
				<view class="upload-desc">支持.png/jpg，10M以内的图片文件</view>
			</view>
			<view class="image-box">
				<u-upload :fileList="fileList" :disabled="true" :deletable="false"
					:maxCount="fileList.length"></u-upload>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				courseId: '', // 课程ID
				courseDetail: {}, // 课程详情
				fileList: [], // 上传的图片列表
			}
		},
		onLoad(options) {
			if (options && options.courseId) {
				this.courseId = options.courseId
				this.getAttendanceDetail();
			}
		},
		methods: {
			getAttendanceDetail() {
				this.$Api.user.getAttendanceDetail({
					id: this.courseId
				}).then(res => {
					this.courseDetail = res.data;
					if (this.courseDetail.image) {
						this.fileList = this.courseDetail.image.split(',').map(item => ({
							url: this.$OssUrl(item, this.courseDetail.oss_url),
							img: item,
						}));
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.to-attendance-box {
		min-height: 100vh;
		background: #f5f6fa;
		padding: 20rpx;
		box-sizing: border-box;

		.course-info {
			background: #fff;
			box-shadow: 0rpx 4rpx 8rpx 0rpx rgba(0, 0, 0, 0.01);
			border-radius: 24rpx;
			padding: 20rpx;
			margin-bottom: 20rpx;

			.item-top {
				display: flex;
				justify-content: space-between;
				padding-bottom: 10rpx;

				.course-title {
					font-size: 30rpx;
					color: #2F1F1A;
					line-height: 42rpx;
					font-weight: bold;
				}

				.course-time {
					font-size: 24rpx;
					color: #333333;
				}
			}

			.item-center {
				display: flex;
				align-items: center;
				padding: 20rpx 0;

				.address-icon {
					width: 32rpx;
					height: 32rpx;
				}

				.address-info {
					flex: 1;
					margin-left: 20rpx;
					margin-right: 20rpx;

					.address-name {
						font-size: 28rpx;
						color: #333333;
					}

					.refresh-address {
						display: flex;
						align-items: center;
						font-size: 24rpx;
						margin-top: 10rpx;

						.label {
							margin-right: 10rpx;
						}

						.active {
							color: #0095F8;
						}

						.refresh-icon {
							width: 20rpx;
							height: 20rpx;
						}
					}
				}

				.clock-in {
					width: 76rpx;
					height: 76rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					background: #0095F8;
					border-radius: 44rpx;
					border: 1rpx solid #0095F8;
					font-weight: 500;
					font-size: 26rpx;
					color: #FFFFFF;
				}
			}

			.item-bottom {
				font-size: 26rpx;
				color: #999999;
				padding-top: 30rpx;
				border-top: 2rpx solid #EEEEEE;

				.bottom-info {
					margin-bottom: 16rpx;

					.value {
						margin-left: 10rpx;
						color: #333333;
					}
				}
			}
		}

		.student-list-box {
			margin-top: 20rpx;
			background: #fff;
			box-shadow: 0rpx 4rpx 8rpx 0rpx rgba(0, 0, 0, 0.01);
			border-radius: 24rpx;
			padding: 20rpx;
			max-height: 600rpx;
			overflow-y: auto;
		}

		.student-list {
			max-height: 600rpx;
			overflow-y: auto;

			.student-item {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 20rpx 0;
				border-bottom: 1rpx solid #EEEEEE;

				&:last-child {
					border-bottom: none;
				}

				.student-name {
					font-size: 28rpx;
					color: #333333;
					width: 120rpx;
				}

				.student-no {
					font-size: 26rpx;
					color: #999999;
					margin-left: 10rpx;
					margin-right: 10rpx;
					flex: 1;
				}

				.student-status {
					display: flex;
					align-items: center;

					.tag-box {
						width: 80rpx;
						height: 40rpx;
						border-radius: 6rpx;
						text-align: center;
						line-height: 40rpx;
						font-weight: 400;
						font-size: 22rpx;
						margin-left: 6rpx;
						background: #F6F6F6;
						color: #606060;
						border: 1rpx solid rgba(0, 0, 0, 0.1);
					}

					.late {
						background: #FFF3ED;
						border: 1rpx solid #FE4F04;
						color: #FE4F04;
					}

					.early {
						background: #FAF1FF;
						border: 1rpx solid #CF77FF;
						color: #CF77FF;
					}

					.absent {
						background: #FFF9ED;
						border: 1rpx solid #F8A500;
						color: #F8A500;
					}

					.success {
						background: #F3FFED;
						border: 1rpx solid #4ED142;
						color: #53D347;
					}
				}
			}
		}



		.upload-box {
			margin-top: 20rpx;
			background: #fff;
			border-radius: 24rpx;
			padding: 32rpx;

			.upload-header {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-bottom: 20rpx;

				.upload-title {
					font-size: 26rpx;
					color: #333333;
					font-weight: bold;
				}

				.upload-desc {
					font-size: 24rpx;
					color: #999999;
				}
			}
		}

		.submit-box {
			margin-top: 44rpx;
			height: 88rpx;
			background: #0095F8;
			box-shadow: 0rpx 4rpx 8rpx 0rpx rgba(0, 149, 248, 0.5);
			border-radius: 44rpx;
			line-height: 88rpx;
			text-align: center;
			font-size: 30rpx;
			color: #FFFFFF;
		}
	}
</style>